import java.util.Stack;


public class RuleCondition {

	Stack<ControlElement> control ;
	Stack<String> stack ;
	Environment environment;
	ControlStructure ct;
	
	public RuleCondition(Stack<ControlElement> control, Stack<String> stack, Environment environment, ControlStructure ct){
		this.control = control;
		this.stack = stack;
		this.environment = environment;
		this.ct = ct;
	}
	
	public static void main(String[] args) {
		Stack<ControlElement> control = new Stack<ControlElement>();
		Stack<String> stack = new Stack<String>();
		Environment environment = new Environment();
		RuleCondition ruleCon = new RuleCondition(control, stack, environment, null);

		// test1 
		control.push(new ControlElement("delta[true]"));
		control.push(new ControlElement("delta[false]"));
		control.push(new ControlElement("beta"));
		stack.push("<false>");
		System.out.println(ruleCon.checkRule());
		//ruleOP.devide();
		//ruleOP.power();
		ruleCon.applyRule();
		System.out.println(ruleCon.control + " " +ruleCon.stack);
	}

	/*
	 * deta[than] delta[else] [beta]
	 */
	public void applyRule() {
		control.pop();
		boolean truthValue = getBoolean(stack.pop());
		ControlCondition elseDelta = (ControlCondition)control.pop();
		ControlCondition thanDelta = (ControlCondition)control.pop();
		if (truthValue == true){
			deltaDump(thanDelta.deltaPointer);
		}else{
			deltaDump(elseDelta.deltaPointer);
		}
	}

	private boolean getBoolean(String pop) {
		if (pop.contains("true")){
			return true;
		}else{
			return false;
		}
	}

	public boolean checkRule() {
		if (control.peek().content.equals("beta"))
			return true;
		else
			return false;
	}

	private void deltaDump(int deltaNo) {
		for (int i = 0; i < ct.delta[deltaNo].size(); i++) {
			control.push(ct.delta[deltaNo].get(i));
		}
	}
}
